var admin = new Vue({
	el : '#container',
	data : {
		currentPageNo : 1,
		pageCount : 1,
		totalRows: 0,
		recordSet : [],
		pageNumbers : [],
		total : 0,
		msg : '',
		allIndices : [],
		indexNameForSearch : '',
		indexInfo : '',
		clusterName : '',
		clusterStatus : '',
		clusterNodes : []
	},
	components : {
		'vue-nav' : Vnav
	},
	methods : {
		resetPageNumbers : function() {
			this.pageNumbers = [];
			var begin = Math
					.round(Math.max(1, this.currentPageNo - 7 / 2));
			var end = Math.round(Math.min(begin + (7 - 1), this.pageCount));
			for (var i = begin; i <= end; i++) {
				this.pageNumbers.push(i);// 重新写入页码数组
			}
		},
		// 有没有更简单的方法，比如整体赋值
		resetRecordSet : function(dataList) {
			this.recordSet = [];
			for (var i = 0; i < dataList.length; i++) {
				this.recordSet.push(dataList[i]);
			}
		},
		resetIndicesSet : function (dataList){
			this.allIndices = [];
			for (var i = 0; i < dataList.length; i++) {
				this.allIndices.push(dataList[i]);
			}
		},
		resetClusterNodeSet : function (dataList){
			this.clusterNodes = [];
			for (var i = 0; i < dataList.length; i++) {
				this.clusterNodes.push(dataList[i]);
			}
		},
		showCreateIndexModal : function() {
			$("#createIndexMoadal").modal("toggle");
		},
		createIndex : function() {
			admin.currentPageNo = 1;
			$.ajax({
				url : '/demo/em/es/createIndex',
				type : "POST",
				async : false,
				data : $("#createIndexForm").serialize(),
				dataType : "TEXT",
				success : function(result) {
					alert(result);
				},
				error : function(result) {
					alert("系统异常");
				}
			});
		},// createIndex
		showCreateTypeModal : function(){
			$.ajax({
				url : '/demo/em/es/loadAllIndices',
				type : "POST",
				async : false,
				dataType : 'JSON',
				success : function(result) {
					admin.resetIndicesSet(result);
					alert(admin.allIndices);
				},
				error : function(result) {
					alert("系统异常");
				}
			});
			
			$("#createTypeMoadal").modal("toggle");
		},
		createType : function() {
			this.currentPageNo = 1;
			var indexName = $("#indexName").val();
			var indexSettings = $("#indexSettings").val();
			$.ajax({
				url : '/demo/em/es/createIndexType',
				type : "POST",
				data : $("#createTypeForm").serialize(),
				async : false,
				dataType : "TEXT",
				success : function(result) {
					alert(result);
				},
				error : function(result) {
					alert("系统异常");
				}
			});
		},// createType
		searchIndex : function() {
			this.currentPageNo = 1;
			var indexName = $("#indexNameForSearch").val();
			$.ajax({
				url : '/demo/em/es/searchIndexByName?indexName=' + indexName,
				type : "POST",
				async : false,
				success : function(result) {
					admin.resetRecordSet(result.dataList);
					admin.pageCount = result.pageCount;
					admin.totalRows=result.sumRows;
					admin.resetPageNumbers();
				},
				error : function(result) {
					alert("系统异常");
				}
			});
		},// search
		showIndexInfoMoadal : function(indexName) {
			$.ajax({
				url : '/demo/em/es/loadIndexByName?indexName=' + indexName,
				type : "POST",
				async : false,
				dataType : "TEXT",
				success : function(result) {
					admin.indexInfo=result;
				},
				error : function(result) {
					alert("系统异常");
				}
			});
			$("#indexInfoMoadal").modal("toggle");
		},// showIndexInfoMoadal
		deleteIndex : function(indexName) {
			this.currentPageNo = 1;
			/*var indexName = $("#indexNameForSearch").val();*/
			$.ajax({
				url : '/demo/em/es/deleteIndex?indexName=' + indexName,
				type : "POST",
				async : false,
				dataType : "TEXT",
				success : function(result) {
					alert(result);
				},
				error : function(result) {
					alert("系统异常");
				}
			});
		},// deleteIndex
		loadClusterInfo : function(indexName) {
			$.ajax({
				url : '/demo/em/es/loadClusterInfo',
				type : "POST",
				async : false,
				dataType : "JSON",
				success : function(result) {
					admin.clusterName = result.name;
					admin.clusterStatus = result.healthStatus;
					admin.resetClusterNodeSet(result.nodeList);
				},
				error : function(result) {
					alert("系统异常");
				}
			});
		},// loadClusterInfo
		importFileData : function(indexName) {
			$.ajax({
				url : '/demo/em/es/importFileData',
				type : "POST",
				async : false,
				dataType : "JSON",
				success : function(result) {
					admin.clusterName = result.name;
					admin.clusterStatus = result.healthStatus;
					admin.resetClusterNodeSet(result.nodeList);
				},
				error : function(result) {
					alert("系统异常");
				}
			});
		},// importFileData
		callback : function(pageNo) {
			this.currentPageNo = pageNo;
			//this.msg = '你点击了' + pageNo + '页';
			$.ajax({
				url : '/demo/em/user/getUserList?pageNo=' + this.currentPageNo,
				type : "POST",
				async : false,
				success : function(result) {
					admin.resetRecordSet(result.dataList);

					admin.pageCount = result.pageCount;
					// this.totalRows=result.sumRows;
					//user.resetPageNumbers();
				},
				error : function(result) {
					alert("系统异常");
				}
			});
		}//callback
	}
// methods area
});
